package com.sheep.jucdemo.part1.part1_11;

/**
 * @Date 2022/4/10 21:12
 * @Created by sheep
 */
public class Test1_11_1 {

    static void print(String str){
        System.out.println(str + ":" + localVariable.get());
        //localVariable.remove();

    }

    static ThreadLocal localVariable = new ThreadLocal<>();

    public static void main(String[] args) {
        Thread threadOne = new Thread(new Runnable() {
            @Override
            public void run() {
                localVariable.set("threadOne local variable");
                print("threadOne");
                System.out.println("threadOne remove after:" + localVariable.get());
            }
        });

        Thread threadTwo = new Thread(new Runnable() {
            @Override
            public void run() {
                localVariable.set("threadTwo local variable");
                print("threadTwo");
                System.out.println("threadTwo remove after:" + localVariable.get());
            }
        });
        threadOne.start();
        threadTwo.start();
    }

}
